package com.whnk.model.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import com.whnk.common.security.annotation.PreAuthorize;
import com.whnk.model.domain.DefTProcessInfo;
import com.whnk.model.service.IDefTProcessInfoService;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.page.TableDataInfo;

/**
 * 流程定义Controller
 *
 * @author whnk
 * @date 2021-10-20
 */
@RestController
@RequestMapping("/workFlow/processDefinition/")
public class DefTProcessInfoController extends BaseController
{
    @Autowired
    private IDefTProcessInfoService defTProcessInfoService;

    /**
     * 查询流程定义列表
     */
    @PreAuthorize(hasPermi = "model:info:list")
    @GetMapping("/list")
    public TableDataInfo list(DefTProcessInfo defTProcessInfo)
    {
        startPage();
        List<DefTProcessInfo> list = defTProcessInfoService.selectProductWorkflowList(defTProcessInfo);
        return getDataTable(list);
    }

    /**
     * 导出流程定义列表
     */
    @PreAuthorize(hasPermi = "model:info:export")
    @Log(title = "导出流程定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefTProcessInfo defTProcessInfo) throws IOException
    {
        List<DefTProcessInfo> list = defTProcessInfoService.selectDefTProcessInfoList(defTProcessInfo);
        ExcelUtil<DefTProcessInfo> util = new ExcelUtil<DefTProcessInfo>(DefTProcessInfo.class);
        util.exportExcel(response, list, "导出流程定义数据");
    }

    /**
     * 获取流程定义详细信息
     */
    @PreAuthorize(hasPermi = "model:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(defTProcessInfoService.selectDefTProcessInfoById(id));
    }

    /**
     * 新增流程定义
     */
    @PreAuthorize(hasPermi = "model:info:add")
    @Log(title = "新增流程定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DefTProcessInfo defTProcessInfo)
    {
        return toAjax(defTProcessInfoService.insertDefTProcessInfo(defTProcessInfo));
    }

    /**
     * 修改流程定义
     */
    @PreAuthorize(hasPermi = "model:info:edit")
    @Log(title = "修改流程定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DefTProcessInfo defTProcessInfo)
    {
        return toAjax(defTProcessInfoService.updateDefTProcessInfo(defTProcessInfo));
    }

    /**
     * 删除流程定义
     */
    @PreAuthorize(hasPermi = "model:info:remove")
    @Log(title = "删除流程定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(defTProcessInfoService.deleteDefTProcessInfoByIds(ids));
    }
}
